<template>
    <div class="container">
        <!-- 绑定对象​
        我们可以给 :class (v-bind:class 的缩写) 传递一个对象来动态切换 class： -->
      <button :class="{ active: isActive }" @click="toggleActive">点我</button>
      <div>
        <img v-if="isActive" src="https://img1.baidu.com/it/u=4061946816,2469956104&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=659"/>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue';
  
  const isActive = ref(false);
  
  function toggleActive() {
    isActive.value = !isActive.value;
  }
  </script>
  
  <style scoped>
  .container {
    text-align: center;
    margin-top: 50px;
    background-color: rgb(236, 236, 236);
    border-radius: 15px;
    padding: 10px;
    margin: 20px;
  }
  
  .active {
    background-color: rgb(245, 231, 81);
    padding: 20px;
    border-radius: 10px;
    transition: background-color 0.3s;
  }
  
  img {
    width: 200px;
    height: auto;
    border-radius: 10px;
  }
  </style>